/*
 * UMLSynch plugin for Eclipse
 * http://umlsynch.googlecode.com
 *
 * Copyright 2008-2010, Evgeny Alexeyev
 * Licensed under the EPL - v1.0
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */

package com.googlecode.umlsynch.eclipse.rpc.dialogs;

import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import com.googlecode.umlsynch.eclipse.rpc.Debug.TEclipseDebug;
import com.googlecode.umlsynch.rpc.base.TConfig;

/**
 * This class demonstrates how to create your own dialog classes. It allows users
 * to input a String
 */
public class RmiConfigDialog extends Dialog {

	public TConfig eclipse;
	public TConfig vpsde;

    private TEclipseDebug debug = new TEclipseDebug("RMI_CONFIG_DIALOG");


  /**
   * InputDialog constructor
   * 
   * @param parent the parent
   */
  public RmiConfigDialog(Shell parent) {
    // Pass the default styles here
    this(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
  }

  /**
   * RmiConfigDialog constructor
   * 
   * @param parent the parent
   * @param style the style
   */
  public RmiConfigDialog(Shell parent, int style) {
    // Let users override the default styles
    super(parent, style);
    setText("RMI Configs");
    eclipse = new TConfig();
    vpsde = new TConfig();
    vpsde.port += 1;
  }

  /**
   * Opens the dialog and returns the input
   * 
   * @return String
   */
  public void open() {
	  
	  // Create the dialog window
      Shell shell = new Shell(getParent(), getStyle());
      
      createContents(shell);
      
      shell.pack();
    
      shell.open();

    
      Display display = getParent().getDisplay();

      while (!shell.isDisposed()) {
    	  if (!display.readAndDispatch()) {
    		  display.sleep();
    	  }
      }

  }

  /**
   * Creates the dialog's contents
   * 
   * @param shell the dialog window
   */
  private void createContents(final Shell shell) {
	
    shell.setLayout(new GridLayout(1, true));
    shell.setText(getText());
        
    TabFolder tabFolder = new TabFolder (shell, SWT.NONE);
    TabItem item = new TabItem (tabFolder, SWT.NULL);
    TabItem item2 = new TabItem (tabFolder, SWT.NULL);
    item.setText ("Eclipse");
    item2.setText ("Visual-Paradigm");    

    Composite compositeTab = new Composite(tabFolder, SWT.NO_FOCUS);
    FillConfigTab(eclipse, compositeTab);

    Composite compositeTab2 = new Composite(tabFolder, SWT.NO_FOCUS);
    FillConfigTab(vpsde, compositeTab2);
    
    item.setControl(compositeTab);
    item2.setControl(compositeTab2);
    tabFolder.setSize (600, 200);
    
    Composite compositeButtons = new Composite(shell, SWT.NO_FOCUS);
    compositeButtons.setLayout(new FillLayout());
    Button ok = new Button(compositeButtons , SWT.PUSH);
    ok.setText("OK");
    ok.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
          shell.close();
        }
    });

    Button cancel = new Button(compositeButtons, SWT.PUSH);
    cancel.setText("Cancel");
    cancel.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
          eclipse = null;
          vpsde = null;
          shell.close();
        }
    });


    // Set the OK button as the default, so
    // user can type input and press Enter
    // to dismiss
    shell.setDefaultButton(ok);
  }

/**
 * @param eclipse2
 * @param compositeTab
 */
private void FillConfigTab(TConfig cfg, Composite compositeTab) {
	compositeTab.setLayout(new GridLayout(2, true));
	compositeTab.setLayoutData(new GridData(400, 200));
    Label label = new Label(compositeTab, SWT.NONE);
    label.setText("Hostname: ");

    Text text = new Text(compositeTab, SWT.NORMAL);
    text.setText(cfg.hostname);
    text.setSize(100, text.getSize().y);
    
    Label label2 = new Label(compositeTab, SWT.NONE);
    label2.setText("Port: ");

    Text text2 = new Text(compositeTab, SWT.NORMAL);
    text2.setText("" + cfg.port);
    text2.setSize(100, text.getSize().y);
    
    Label label3 = new Label(compositeTab, SWT.NONE);
    label3.setText("Interface: ");
    
    Text text3 = new Text(compositeTab, SWT.NORMAL);
    text3.setText("SimpleRMI");
    text3.setSize(100, text.getSize().y);
}
}
